package ldh.im.fxgui.demo;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
import ldh.im.fxbase.richtext.ImTextPane;
import org.fxmisc.flowless.Cell;
import org.fxmisc.flowless.VirtualFlow;
import org.fxmisc.flowless.VirtualizedScrollPane;

import java.util.ArrayList;
import java.util.List;

public class EmojiTest2 extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        ObservableList<String> items = FXCollections.observableArrayList();
        VirtualFlow<String, ?> messageList = VirtualFlow.createVertical(items, m->{
            return Cell.wrapNode(createMessagePane(m));
        });;

        VirtualizedScrollPane virtualizedScrollPane = new VirtualizedScrollPane<>(messageList);
        Scene scene = new Scene(virtualizedScrollPane, 600, 300);
        primaryStage.setScene(scene);
        primaryStage.show();

        int total = 1000000;
        List<String> result = new ArrayList(total);
        for (int i=0; i<total; i++) {
            result.add(i + "\tsdafad啊是打发法啊是打发法阿凡达发按时打发啊十大地方按时打发啊打发" +
                    "阿德撒法发按时打发发撒打发发达是啊萨顶顶发啊打发是奥数");
        }
        items.addAll(result);
    }

    private Node createMessagePane(String message) {
        ImTextPane imTextPane = new ImTextPane(TextAlignment.LEFT);
        imTextPane.setContent(message);
        return imTextPane;
    }
}
